/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.inf.ufg.model;

import br.inf.ufg.factory.ConexaoFactoryMySql;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.swing.*;


/**
 *
 * @author alunoinf
 */
public class LoginDAO {
    
   
    private Statement stmt ;
    private ResultSet rs;
    private Connection con;
    
    public  LoginDAO() throws SQLException, ClassNotFoundException{
        
             con = ConexaoFactoryMySql.getConnection();
             stmt = con.createStatement();
             
    }
    
   
    public boolean autencarUsuario(Operadores operador) throws SQLException, Exception{
        
        //return false;
        
        
        String Login = operador.getLogin();
        String Senha = operador.getSenha();
        
        
       
            String sql = " Select * from operadores " + 
                         " where login  = '" + Login + "' " + 
                         " and senha    =  '" + Senha +"'";

            //Statement = con.createStatement();
             //ResultSet = Statement.executeQuery(sql);
            rs = stmt.executeQuery(sql);
                    
            if (rs.first()) {
                if (rs.getInt("IS_ATIVO") == 0){
                    throw new Exception("Usuário inativo");
                }else{
                    return true;
                }  
            }else{
                throw new Exception("Usuário / Senha inválidos");
            }
        
        

     }          
        
        
         
}
